home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / regicon / frmregs4.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-05-07  |  20.1 KB  |  616 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "RegiCon Test"
  4.    ClientHeight    =   6765
  5.    ClientLeft      =   2865
  6.    ClientTop       =   1995
  7.    ClientWidth     =   7365
  8.    Height          =   7170
  9.    Left            =   2805
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   6765
  12.    ScaleWidth      =   7365
  13.    Top             =   1650
  14.    Width           =   7485
  15.    Begin VB.ListBox List2 
  16.       Height          =   1230
  17.       Left            =   1200
  18.       TabIndex        =   32
  19.       Top             =   5400
  20.       Width           =   3975
  21.    End
  22.    Begin VB.ListBox List1 
  23.       Height          =   1230
  24.       Left            =   1200
  25.       TabIndex        =   31
  26.       Top             =   4080
  27.       Width           =   3975
  28.    End
  29.    Begin VB.CommandButton cmdEnumEntry 
  30.       Caption         =   "Enumerate Entry"
  31.       Height          =   375
  32.       Left            =   5400
  33.       TabIndex        =   17
  34.       Top             =   1200
  35.       Width           =   1815
  36.    End
  37.    Begin VB.CommandButton cmdIsKey 
  38.       Caption         =   "Does Key Exist?"
  39.       Height          =   375
  40.       Left            =   5400
  41.       TabIndex        =   16
  42.       Top             =   840
  43.       Width           =   1815
  44.    End
  45.    Begin VB.CommandButton cmdExit 
  46.       Caption         =   "Exit"
  47.       Height          =   375
  48.       Left            =   5400
  49.       TabIndex        =   22
  50.       Top             =   3240
  51.       Width           =   1815
  52.    End
  53.    Begin VB.CommandButton cmdIsItem 
  54.       Caption         =   "Does Item Exist?"
  55.       Height          =   375
  56.       Left            =   5400
  57.       TabIndex        =   21
  58.       Top             =   2760
  59.       Width           =   1815
  60.    End
  61.    Begin VB.CommandButton cmdDeleteKeyItem 
  62.       Caption         =   "Delete Item"
  63.       Height          =   375
  64.       Left            =   5400
  65.       TabIndex        =   20
  66.       Top             =   2400
  67.       Width           =   1815
  68.    End
  69.    Begin VB.CommandButton cmdGetKeyItem 
  70.       Caption         =   "Get Item"
  71.       Height          =   375
  72.       Left            =   5400
  73.       TabIndex        =   19
  74.       Top             =   2040
  75.       Width           =   1815
  76.    End
  77.    Begin VB.CommandButton cmdSetKeyItem 
  78.       Caption         =   "Set Item"
  79.       Height          =   375
  80.       Left            =   5400
  81.       TabIndex        =   18
  82.       Top             =   1680
  83.       Width           =   1815
  84.    End
  85.    Begin VB.CommandButton cmdDeleteKey 
  86.       Caption         =   "Delete Key"
  87.       Height          =   375
  88.       Left            =   5400
  89.       TabIndex        =   15
  90.       Top             =   480
  91.       Width           =   1815
  92.    End
  93.    Begin VB.CommandButton cmdCreateKey 
  94.       Caption         =   "Create Key"
  95.       Height          =   375
  96.       Left            =   5400
  97.       TabIndex        =   14
  98.       Top             =   120
  99.       Width           =   1815
  100.    End
  101.    Begin VB.TextBox txtItemValue 
  102.       Height          =   285
  103.       Left            =   1200
  104.       MultiLine       =   -1  'True
  105.       TabIndex        =   13
  106.       Text            =   "frmRegs4.frx":0000
  107.       Top             =   3240
  108.       Width           =   3975
  109.    End
  110.    Begin VB.Frame Frame1 
  111.       Caption         =   "Data Type"
  112.       Height          =   1215
  113.       Left            =   1200
  114.       TabIndex        =   28
  115.       Top             =   1920
  116.       Width           =   3975
  117.       Begin VB.OptionButton optType 
  118.          Caption         =   "DWord MSB"
  119.          Height          =   255
  120.          Index           =   8
  121.          Left            =   2640
  122.          TabIndex        =   12
  123.          Top             =   800
  124.          Width           =   1215
  125.       End
  126.       Begin VB.OptionButton optType 
  127.          Caption         =   "DWord LSB"
  128.          Height          =   255
  129.          Index           =   7
  130.          Left            =   2640
  131.          TabIndex        =   11
  132.          Top             =   520
  133.          Width           =   1215
  134.       End
  135.       Begin VB.OptionButton optType 
  136.          Caption         =   "Link"
  137.          Height          =   255
  138.          Index           =   6
  139.          Left            =   2640
  140.          TabIndex        =   10
  141.          Top             =   240
  142.          Width           =   1215
  143.       End
  144.       Begin VB.OptionButton optType 
  145.          Caption         =   "Not Defined"
  146.          Height          =   255
  147.          Index           =   5
  148.          Left            =   1080
  149.          TabIndex        =   9
  150.          Top             =   800
  151.          Width           =   1455
  152.       End
  153.       Begin VB.OptionButton optType 
  154.          Caption         =   "Expand String"
  155.          Height          =   255
  156.          Index           =   4
  157.          Left            =   1080
  158.          TabIndex        =   8
  159.          Top             =   520
  160.          Width           =   1455
  161.       End
  162.       Begin VB.OptionButton optType 
  163.          Caption         =   "Multi-line String"
  164.          Height          =   255
  165.          Index           =   3
  166.          Left            =   1080
  167.          TabIndex        =   7
  168.          Top             =   240
  169.          Width           =   1455
  170.       End
  171.       Begin VB.OptionButton optType 
  172.          Caption         =   "Binary"
  173.          Height          =   255
  174.          Index           =   2
  175.          Left            =   120
  176.          TabIndex        =   6
  177.          Top             =   800
  178.          Width           =   975
  179.       End
  180.       Begin VB.OptionButton optType 
  181.          Caption         =   "DWord"
  182.          Height          =   255
  183.          Index           =   1
  184.          Left            =   120
  185.          TabIndex        =   5
  186.          Top             =   520
  187.          Width           =   975
  188.       End
  189.       Begin VB.OptionButton optType 
  190.          Caption         =   "String"
  191.          Height          =   255
  192.          Index           =   0
  193.          Left            =   120
  194.          TabIndex        =   4
  195.          Top             =   240
  196.          Value           =   -1  'True
  197.          Width           =   975
  198.       End
  199.    End
  200.    Begin VB.TextBox txtItemName 
  201.       Height          =   285
  202.       Left            =   1200
  203.       TabIndex        =   3
  204.       Top             =   1560
  205.       Width           =   3975
  206.    End
  207.    Begin VB.TextBox txtSubKey 
  208.       Height          =   285
  209.       Left            =   1200
  210.       TabIndex        =   2
  211.       Top             =   1080
  212.       Width           =   3975
  213.    End
  214.    Begin VB.TextBox txtKey 
  215.       Height          =   285
  216.       Left            =   1200
  217.       TabIndex        =   1
  218.       Text            =   "SOFTWARE\test"
  219.       Top             =   600
  220.       Width           =   3975
  221.    End
  222.    Begin VB.ComboBox cboRoot 
  223.       Height          =   315
  224.       Left            =   1200
  225.       TabIndex        =   0
  226.       Top             =   120
  227.       Width           =   3975
  228.    End
  229.    Begin VB.Label Label7 
  230.       Alignment       =   1  'Right Justify
  231.       Caption         =   "Items:"
  232.       Height          =   255
  233.       Left            =   240
  234.       TabIndex        =   30
  235.       Top             =   5280
  236.       Width           =   855
  237.    End
  238.    Begin VB.Label Label6 
  239.       Alignment       =   1  'Right Justify
  240.       Caption         =   "Sub-Keys:"
  241.       Height          =   255
  242.       Left            =   240
  243.       TabIndex        =   29
  244.       Top             =   4080
  245.       Width           =   855
  246.    End
  247.    Begin RegistryControl.RegiCon RegiCon1 
  248.       Left            =   360
  249.       Top             =   2160
  250.       _ExtentX        =   847
  251.       _ExtentY        =   847
  252.    End
  253.    Begin VB.Label Label5 
  254.       Alignment       =   1  'Right Justify
  255.       Caption         =   "Value:"
  256.       Height          =   255
  257.       Left            =   360
  258.       TabIndex        =   27
  259.       Top             =   3240
  260.       Width           =   735
  261.    End
  262.    Begin VB.Label Label4 
  263.       Alignment       =   1  'Right Justify
  264.       Caption         =   "Item:"
  265.       Height          =   255
  266.       Left            =   120
  267.       TabIndex        =   26
  268.       Top             =   1560
  269.       Width           =   855
  270.    End
  271.    Begin VB.Label Label3 
  272.       Alignment       =   1  'Right Justify
  273.       Caption         =   "Sub-Key:"
  274.       Height          =   255
  275.       Left            =   120
  276.       TabIndex        =   25
  277.       Top             =   1080
  278.       Width           =   975
  279.    End
  280.    Begin VB.Label Label2 
  281.       Alignment       =   1  'Right Justify
  282.       Caption         =   "Key:"
  283.       Height          =   255
  284.       Left            =   240
  285.       TabIndex        =   24
  286.       Top             =   600
  287.       Width           =   855
  288.    End
  289.    Begin VB.Label Label1 
  290.       Alignment       =   1  'Right Justify
  291.       Caption         =   "Root-Key:"
  292.       Height          =   255
  293.       Left            =   120
  294.       TabIndex        =   23
  295.       Top             =   120
  296.       Width           =   975
  297.    End
  298. Attribute VB_Name = "Form1"
  299. Attribute VB_Creatable = False
  300. Attribute VB_Exposed = False
  301. Private Sub Command3_Click()
  302. End Sub
  303. Option Explicit
  304. Private Sub cboRoot_Click()
  305.     '
  306.     'the SubKeyNames() array and ItemNames() array
  307.     'are only valid after an EnumerateEntry method
  308.     'so we clear the list to prevent any confusion
  309.     List1.Clear
  310.     List2.Clear
  311. End Sub
  312. Private Sub cmdCreateKey_Click()
  313.     If Trim$(txtKey.Text) = "" Then
  314.         MsgBox "Must specify a Key", vbInformation, "No Key"
  315.         Exit Sub
  316.     End If
  317.     '
  318.     'When you use the SetEntry method without
  319.     'specifying a KeyItemName, an empty key is created
  320.     'in the registry
  321.     RegiCon1.RootKey = cboRoot.ListIndex
  322.     RegiCon1.Key = txtKey.Text
  323.     RegiCon1.KeyItemName = ""
  324.     RegiCon1.SetEntry
  325.     '
  326.     'the SubKeyNames() array and ItemNames() array
  327.     'are only valid after an EnumerateEntry method
  328.     'so we clear the list to prevent any confusion
  329.     List1.Clear
  330.     List2.Clear
  331. End Sub
  332. Private Sub cmdDeleteKey_Click()
  333.     If Trim$(txtKey.Text) = "" Then
  334.         MsgBox "Must specify a Key", vbInformation, "No Key"
  335.         Exit Sub
  336.     End If
  337.     If txtSubKey.Text = "" Then
  338.         MsgBox "You have chosen to delete a key directly off of a RootKey!" & vbCr & vbCrLf _
  339.             & "Although you can create keys directly off of HKEY_CLASSES_ROOT or HKEY_CURRENT_USER," & vbCrLf _
  340.             & "deleting a key from a root key is NOT normal and this sample will NOT delete this key!" & vbCr & vbCrLf _
  341.             & "Normally you should use the SubKey property to specify which portion of the multikey to delete (see the Help File)." & vbCr & vbCrLf _
  342.             , vbExclamation, "Delete Prevented By Sample!"
  343.         Exit Sub
  344.     Else
  345.         If MsgBox("Are you sure you want to delete the subkey '" & txtSubKey.Text & "' from the key '" & txtKey.Text & "'?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete Key") = vbNo Then
  346.             Exit Sub
  347.         End If
  348.     End If
  349.     '
  350.     'To delete a Key and any of its subkeys and items,
  351.     'set Key to the parent key of the subkey to delete;
  352.     'set the SubKey to the key that you want to delete;
  353.     '
  354.     'To delete an entire key, do NOT specify a KeyItemName, otherwise
  355.     'the control will only delete the item
  356.     RegiCon1.RootKey = cboRoot.ListIndex
  357.     RegiCon1.Key = txtKey.Text
  358.     RegiCon1.SubKey = txtSubKey.Text
  359.     RegiCon1.KeyItemName = ""
  360.     RegiCon1.DeleteEntry
  361.     txtSubKey.Text = ""
  362.     txtItemValue.Text = ""
  363.     '
  364.     'the SubKeyNames() array and ItemNames() array
  365.     'are only valid after an EnumerateEntry method
  366.     'so we clear the list to prevent any confusion
  367.     List1.Clear
  368.     List2.Clear
  369. End Sub
  370. Private Sub cmdDeleteKeyItem_Click()
  371.     If Trim$(txtKey.Text) = "" Then
  372.         MsgBox "Must specify a Key", vbInformation, "No Key"
  373.         Exit Sub
  374.     ElseIf Trim$(txtItemName) = "" Then
  375.         MsgBox "Must specify an Item", vbInformation, "No Item"
  376.         Exit Sub
  377.     End If
  378.     If MsgBox("Are you sure you want to delete the item '" & txtItemName.Text & "'?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete Item") = vbNo Then
  379.         Exit Sub
  380.     End If
  381.     'to delete an item from a key, specify
  382.     'the key and set the KeyItemName to the item
  383.     'that you want to delete
  384.     RegiCon1.RootKey = cboRoot.ListIndex
  385.     RegiCon1.Key = txtKey.Text
  386.     RegiCon1.KeyItemName = txtItemName.Text
  387.     RegiCon1.DeleteEntry
  388.     txtItemName.Text = ""
  389.     txtItemValue.Text = ""
  390.     '
  391.     'the SubKeyNames() array and ItemNames() array
  392.     'are only valid after an EnumerateEntry method
  393.     'so we clear the list to prevent any confusion
  394.     List1.Clear
  395.     List2.Clear
  396. End Sub
  397. Private Sub cmdEnumEntry_Click()
  398.     '
  399.     'clear any previous results
  400.     List1.Clear
  401.     List2.Clear
  402.     RegiCon1.RootKey = cboRoot.ListIndex
  403.     RegiCon1.Key = txtKey.Text
  404.     RegiCon1.KeyItemName = ""
  405.     RegiCon1.EnumerateEntry
  406.     '
  407.     'loop through both arrays, displaying
  408.     'the results
  409.     Dim l As Long
  410.     For l = 0 To RegiCon1.SubKeysCount - 1
  411.         List1.AddItem RegiCon1.SubKeyNames(l)
  412.     Next l
  413.     l = 0
  414.     For l = 0 To RegiCon1.ItemsCount - 1
  415.         List2.AddItem RegiCon1.ItemNames(l)
  416.     Next l
  417. End Sub
  418. Private Sub cmdExit_Click()
  419.     Unload Me
  420. End Sub
  421. Private Sub cmdGetKeyItem_Click()
  422.     Dim str As String
  423.     Dim i As Integer
  424.     txtItemValue.Text = ""
  425.     If Trim$(txtKey.Text) = "" Then
  426.         MsgBox "Must specify a Key", vbInformation, "No Key"
  427.         Exit Sub
  428.     'ElseIf Trim$(txtItemName) = "" Then
  429.     '    MsgBox "Must specify an Item", vbInformation, "No Item"
  430.     '    Exit Sub
  431.     End If
  432.     '
  433.     'to retrieve an item, specify the
  434.     'Key and KeyItemName, then call the
  435.     'GetEntry method. The KeyItemType and
  436.     'KeyItemValue properties will contain the
  437.     'data type and value, respectively.
  438.     '
  439.     'If unable to open/locate the item, the type
  440.     'will be REG_NONE and the value will be null
  441.     RegiCon1.RootKey = cboRoot.ListIndex
  442.     RegiCon1.Key = txtKey.Text
  443.     RegiCon1.KeyItemName = txtItemName.Text
  444.     RegiCon1.GetEntry
  445.     str = "Value: " & CStr(RegiCon1.KeyItemValue) & vbCr & vbCrLf
  446.     i = RegiCon1.KeyItemType
  447.     Select Case i
  448.         Case dtREG_SZ
  449.             str = str & "Type: REG_SZ"
  450.             optType(0).Value = True
  451.         Case dtREG_DWORD
  452.             str = str & "Type: REG_DWORD"
  453.             optType(1).Value = True
  454.         Case dtREG_BINARY
  455.             str = str & "Type: REG_BINARY"
  456.             optType(2).Value = True
  457.         Case dtREG_MULTI_SZ
  458.             str = str & "Type: REG_MULTI_SZ"
  459.             optType(3).Value = True
  460.         Case dtREG_EXPAND_SZ
  461.             str = str & "Type: REG_EXPAND_SZ"
  462.             optType(4).Value = True
  463.         Case dtREG_NONE
  464.             str = str & "Type: REG_NONE"
  465.             optType(5).Value = True
  466.         Case dtREG_LINK
  467.             str = str & "Type: REG_LINK"
  468.             optType(6).Value = True
  469.         Case dtREG_DWORD_LITTLE_ENDIAN
  470.             'this will never happen because REG_DWORD_LITTLE_ENDIAN
  471.             'and DWord are the same thing.
  472.             str = str & "Type: REG_DWORD_LITTLE_ENDIAN"
  473.             optType(7).Value = True
  474.         Case dtREG_DWORD_BIG_ENDIAN
  475.             str = str & "Type: REG_DWORD_BIG_ENDIAN"
  476.             optType(8).Value = True
  477.         Case Else
  478.             'list is not implemented
  479.             str = str & "Type: Other (" & CStr(i) & ")"
  480.             optType(5).Value = True
  481.     End Select
  482.     txtItemValue.Text = CStr(RegiCon1.KeyItemValue)
  483.     '
  484.     'the SubKeyNames() array and ItemNames() array
  485.     'are only valid after an EnumerateEntry method
  486.     'so we clear the list to prevent any confusion
  487.     List1.Clear
  488.     List2.Clear
  489.     '
  490.     'display the results
  491.     MsgBox str
  492. End Sub
  493. Private Sub cmdIsItem_Click()
  494.     If Trim$(txtKey.Text) = "" Then
  495.         MsgBox "Must specify a Key", vbInformation, "No Key"
  496.         Exit Sub
  497.     ElseIf Trim$(txtItemName) = "" Then
  498.         MsgBox "Must specify an Item", vbInformation, "No Item"
  499.         Exit Sub
  500.     End If
  501.     RegiCon1.RootKey = cboRoot.ListIndex
  502.     RegiCon1.Key = txtKey.Text
  503.     RegiCon1.KeyItemName = txtItemName.Text
  504.         
  505.     If (RegiCon1.IsEntry) Then
  506.         MsgBox "This IS an Item:" & vbCr & vbCrLf & "Key = " & txtKey.Text & vbCrLf & "Item = " & txtItemName
  507.     Else
  508.         MsgBox "This IS NOT an Item:" & vbCr & vbCrLf & "Key = " & txtKey.Text & vbCrLf & "Item = " & txtItemName
  509.     End If
  510.     '
  511.     'the SubKeyNames() array and ItemNames() array
  512.     'are only valid after an EnumerateEntry method
  513.     'so we clear the list to prevent any confusion
  514.     List1.Clear
  515.     List2.Clear
  516. End Sub
  517. Private Sub cmdIsKey_Click()
  518.     If Trim$(txtKey.Text) = "" Then
  519.         MsgBox "Must specify a Key", vbInformation, "No Key"
  520.         Exit Sub
  521.     End If
  522.         
  523.     RegiCon1.RootKey = cboRoot.ListIndex
  524.     RegiCon1.Key = txtKey.Text
  525.     RegiCon1.KeyItemName = ""
  526.         
  527.     If (RegiCon1.IsEntry) Then
  528.         MsgBox "This IS an entry:" & vbCr & vbCrLf & "Key = " & txtKey.Text
  529.     Else
  530.         MsgBox "This IS NOT an entry:" & vbCr & vbCrLf & "Key = " & txtKey.Text
  531.     End If
  532.     '
  533.     'the SubKeyNames() array and ItemNames() array
  534.     'are only valid after an EnumerateEntry method
  535.     'so we clear the list to prevent any confusion
  536.     List1.Clear
  537.     List2.Clear
  538. End Sub
  539. Private Sub cmdSetKeyItem_Click()
  540.     '
  541.     'To set a key item, call the SetEntry
  542.     'method after specifying a Key, KeyItemName,
  543.     'KeyItemType and appropriate KeyItemValue
  544.     If Trim$(txtKey.Text) = "" Then
  545.         MsgBox "Must specify a Key", vbInformation, "No Key"
  546.         Exit Sub
  547.     ElseIf Trim$(txtItemName) = "" Then
  548.         MsgBox "Must specify an Item", vbInformation, "No Item"
  549.         Exit Sub
  550.     End If
  551.     RegiCon1.RootKey = cboRoot.ListIndex
  552.     RegiCon1.Key = txtKey.Text
  553.     RegiCon1.KeyItemName = txtItemName.Text
  554.     RegiCon1.KeyItemValue = txtItemValue.Text
  555.     RegiCon1.SetEntry
  556.     '
  557.     'the SubKeyNames() array and ItemNames() array
  558.     'are only valid after an EnumerateEntry method
  559.     'so we clear the list to prevent any confusion
  560.     List1.Clear
  561.     List2.Clear
  562. End Sub
  563. Private Sub Form_Load()
  564.     Dim TempString As String
  565.     cboRoot.AddItem "HKEY_LOCAL_MACHINE", 0
  566.     cboRoot.AddItem "HKEY_CURRENT_USER", 1
  567.     cboRoot.AddItem "HKEY_CURRENT_CONFIG", 2
  568.     cboRoot.AddItem "HKEY_USERS", 3
  569.     cboRoot.AddItem "HKEY_CLASSES_ROOT", 4
  570.     cboRoot.AddItem "HKEY_DYN_DATA", 5
  571.     cboRoot.ListIndex = 0
  572.     RegiCon1.KeyItemType = 0
  573.     Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
  574.     TempString = "The following sample demonstrates the Mabry RegiCon OCX." & vbCr & vbCrLf & _
  575.                 "When using this sample, you have direct access to your system registry " & _
  576.                 "and you can add, delete, and change the contents of your current registry settings. " & vbCr & vbCrLf & _
  577.                 "You are STRONGLY encouraged to use this sample application " & _
  578.                 "to create some TEST keys and items, then edit and delete the test entries." & vbCr & vbCrLf & _
  579.                 "Further, a thorough understanding of the how the Key and SubKey properties work together to delete " & _
  580.                 "keys is highly recommended."
  581.                 
  582.     MsgBox TempString, vbInformation, "READ ME!"
  583. End Sub
  584. Private Sub List1_Click()
  585.     If List1.ListIndex < 0 Then
  586.         Exit Sub
  587.     End If
  588.     txtItemName.Text = ""
  589.     If txtKey.Text <> "" Then
  590.         txtKey.Text = RegiCon1.Key & "\" & List1.List(List1.ListIndex)
  591.     Else
  592.         txtKey.Text = List1.List(List1.ListIndex)
  593.     End If
  594. End Sub
  595. Private Sub List2_Click()
  596.     If List2.ListIndex < 0 Then
  597.         Exit Sub
  598.     End If
  599.     txtKey.Text = RegiCon1.Key
  600.     txtItemName.Text = List2.List(List2.ListIndex)
  601. End Sub
  602. Private Sub optType_Click(Index As Integer)
  603.     Static i As Integer
  604.     If i = Index Then
  605.         Exit Sub
  606.     End If
  607.     If Index = 2 Or Index = 3 Then
  608.         txtItemValue.Height = 885
  609.     Else
  610.         txtItemValue.Height = 285
  611.     End If
  612.     RegiCon1.KeyItemType = Index
  613.     i = Index
  614.     txtItemValue.Text = ""
  615. End Sub
  616.